/*
 * Gaussian.java
 *
 * Created on Dec 21, 2011
 *
 * Copyright (c) 2011 Artur Rataj.
 *
 * This code is distributed under the terms of the GNU Library
 * General Public License, either version 3 of the license or, at
 * your option, any later version.
 */

package pl.gliwice.iitis.spatialnn.network.construct;

import java.util.*;

/**
 * A Gaussian distribution, represented by a mean and a standard deviation.
 * 
 * @author Artur Rataj
 */
public class Gaussian {
    /**
     * Expectation.
     */
    double mean;
    /**
     * Standard deviation.
     */
    double sigma;
    /**
     * A generator of random numbers.
     */
    static Random random = new Random(3);
    
    /**
     * Creates a new instance of <code>Gaussian</code>.
     * 
     * @param mean mean value
     * @param sigma standard deviation
     */
    public Gaussian(double mean, double sigma) {
        this.mean = mean;
        this.sigma = sigma;
    }
    /**
     * Creates a new instance of <code>Gaussian</code>.
     * 
     * @param orig a gaussian object to deep copy
     */
    public Gaussian(Gaussian orig) {
        this.mean = orig.mean;
        this.sigma = orig.sigma;
    }
    /**
     * Draws a value from the normal distribution.
     * 
     * @param mean expected value
     * @param sigma standard deviation
     * @return the value drawn
     */
    public static double normal(double mean, double sigma) {
        return random.nextGaussian()*sigma + mean;
    }
    /**
     * Draws a value from this gaussian.
     * 
     * @return a random value
     */
    public double draw() {
        return normal(mean, sigma);
    }
    @Override
    public String toString() {
        return "Normal(mean=" + mean + " sigma=" + sigma + ")";
    }
}
